﻿using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using QQ.Client;
using QQ.Packet;
using System;
using System.Collections.Generic;

namespace QQ.Codecs
{
    public class IncomingDecoder : MessageToMessageDecoder<IByteBuffer>
    {
        public override bool IsSharable => true;

        private readonly LoginSigInfo loginSigInfo;
        private readonly HeadPacket headPacket;

        public IncomingDecoder(HeadPacket headPacket, LoginSigInfo loginSigInfo)
        {
            this.loginSigInfo = loginSigInfo;
            this.headPacket = headPacket;
        }

        protected override void Decode(IChannelHandlerContext context, IByteBuffer msg, List<object> output)
        {
            Console.WriteLine($"从服务器接收到：{msg.ReadableBytes}个字节");
            headPacket.Deserialize(msg);
            output.Add(headPacket);
        }
    }
}